"""检查API返回的数据范围"""
import requests
from datetime import datetime

# 请求API
url = "http://45.26.199.6:8000/api/stocks/sh600519/history?days=90"
response = requests.get(url, timeout=15)

if response.status_code == 200:
    data = response.json()
    print(f"✅ API返回 {len(data)} 条数据\n")
    
    # 显示最后5条
    print("📊 最后5条数据:")
    for i, item in enumerate(data[-5:]):
        date = datetime.fromtimestamp(item['timestamp'] / 1000).strftime('%Y-%m-%d')
        idx = len(data) - 5 + i
        print(f"  [{idx}] {date} - 收盘: ¥{item['close']}")
    
    # 数据范围
    first_date = datetime.fromtimestamp(data[0]['timestamp'] / 1000).strftime('%Y-%m-%d')
    last_date = datetime.fromtimestamp(data[-1]['timestamp'] / 1000).strftime('%Y-%m-%d')
    
    print(f"\n{'='*60}")
    print(f"起始: {first_date} | 结束: {last_date} | 今天: {datetime.now().strftime('%Y-%m-%d')}")
    print(f"{'='*60}")
else:
    print(f"❌ API错误: {response.status_code}")



